import 'package:flutter/material.dart';
import 'package:tiktokadult/hj_page/home_business/search_page/search_result_page/search_acg_result_page.dart';
import 'package:tiktokadult/hj_page/home_business/search_page/search_result_page/search_user_result_page.dart';
import 'package:tiktokadult/hj_page/home_business/search_page/search_result_page/search_video_result_page.dart';

import '../../../../tools_base/indicator/custom_tab_indicator.dart';
import '../widget/search_app_bar.dart';

class SearchResultMainPage extends StatefulWidget {
  final String keywords;

  const SearchResultMainPage(this.keywords, {super.key});

  @override
  State<StatefulWidget> createState() {
    return _SearchResultMainPageState();
  }
}

class _SearchResultMainPageState extends State<SearchResultMainPage> with SingleTickerProviderStateMixin {
  final typeList = ['短视频','视频',  '帖子', '用户', '色图', '小说', '种子', '黄油'];

  late final TabController tabCtr = TabController(length: typeList.length, vsync: this);
  late String keywords = widget.keywords;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          SearchAppBar(
            onSubmitted: (value) {
              keywords = value;
              setState(() {});
            },
          ),
          Container(
            height: 32,
            child: TabBar(
              tabAlignment: TabAlignment.start,
              tabs: typeList.map((e) {
                return Container(
                  padding: EdgeInsets.symmetric(horizontal: 12),
                  child: Text(e),
                );
              }).toList(),
              labelStyle: TextStyle(fontSize: 14),
              labelColor: Color(0xE5FFFFFF),
              unselectedLabelStyle: TextStyle(fontSize: 14),
              unselectedLabelColor: Color(0x73FFFFFF),
              controller: tabCtr,
              padding: EdgeInsets.zero,
              isScrollable: true,
              labelPadding: EdgeInsets.zero,
              indicator: BoxDecoration(),
              // indicator: CustomIndicator(
              //   height: 4,
              //   width: 16,
              //   useGradient: true,
              //   gradientColors: [
              //     Color(0x00E1351F),
              //     Color(0xFFE1351F),
              //   ],
              //   offsetY: 4,
              // ),
            ),
          ),
          Expanded(
            child: TabBarView(
              controller: tabCtr,
              children: [
                SearchVideoResultPage(key: ValueKey("0$keywords"), keywords: keywords, type: SearchType.short),
                SearchVideoResultPage(key: ValueKey("1$keywords"), keywords: keywords, type: SearchType.video),
                SearchVideoResultPage(key: ValueKey("2$keywords"), keywords: keywords, type: SearchType.post),
                SearchUserResultPage(key: ValueKey("3$keywords"), keywords: keywords, type: SearchType.user),
                SearchVideoResultPage(key: ValueKey("4$keywords"), keywords: keywords, type: SearchType.image),
                SearchACGResultPage(key: ValueKey("5$keywords"), keywords: keywords, type: SearchType.novel),
                SearchVideoResultPage(key: ValueKey("6$keywords"), keywords: keywords, type: SearchType.seed),
                SearchVideoResultPage(key: ValueKey("7$keywords"), keywords: keywords, type: SearchType.game),
              ],
            ),
          ),
        ],
      ),
      // body: Column(
      //   children: [
      //     SearchAppBar(onSubmitted: (value) => controller.searchEvent(value)),
      //     SearchResultHader(
      //       tabController: controller.tabCtr,
      //       tabs: controller.typeList,
      //     ),
      //     Expanded(
      //       child: TabBarView(
      //         controller: controller.tabCtr,
      //         children: controller.instanceChildren(),
      //       ),
      //     ),
      //   ],
      // ),
    );
  }
}
